package com.hzqy.commons.service.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OrderXmlUtils {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());

	/**
	 * 发请求
	 *
	 */
	public static String sendPost(String url,int readTimeOut,int connectTimeout,String cookiesValue) throws Exception{
		HttpURLConnection conn = null;
		String Result = null;
		InputStream is=null;
		try {
			URL url1 = new URL(url);
			conn = (HttpURLConnection) url1.openConnection();
			conn.setRequestMethod("GET");
			conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
			conn.setRequestProperty("Accept", "text/html, application/xhtml+xml, */*");
			conn.setRequestProperty("Connection", "Keep-Alive");
			/*conn.setRequestProperty("Cookie", cookiesValue);*/
			conn.setUseCaches(false);
			conn.setDoOutput(true);
			conn.setReadTimeout(readTimeOut);
			conn.setConnectTimeout(connectTimeout);

			is = conn.getInputStream();
			int resp = 0;
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			while((resp = is.read())!=-1) {
				bos.write(resp);
			}
			Result = new String(bos.toByteArray(),"UTF-8");
		} catch (IOException e) {
			e.printStackTrace(System.out);
			throw e;
		} finally {
			if (conn != null)
				conn.disconnect();
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
				}
			}
		}
		return Result;
	}
}
